import {
  wxRequest
} from '../../utils/server.js';
const _wxRequest = new wxRequest();
const app = getApp()

Page({
  data: {
    imgUrl: app.globalData.imgUrl,
    hasNextPage: false,
    uploadUrl: wx.getStorageSync('uploadUrl'),
    list: [],
    pageNo: 1
  },

  onShow: function() {
    this.getlist();
  },
  
  //跳转详情页 
  toStoreDetail(e) {
    var id = e.currentTarget.dataset.id
    console.log(e)
    wx.navigateTo({
      url: '/pages/store/detail?id=' + id,
    })
  },


  //查询列表
  getlist: function() {
    this.storeRequest()
  },


  //店铺请求
  storeRequest: function() {
    _wxRequest.wxTonkenAjax({
      url: app.globalData.apiUrl + '/org/protected/storeAttend/findUserAttend?pageNo=' + this.data.pageNo + '&pageSize=10',
      method: 'POST'
    }, (res) => {
      let list = res.list;
      if (this.data.pageNo !== 1) {
        list = this.data.list.concat(list);
      }
      this.setData({
        list: list,
        pageNo: res.page.pageNo,
        hasNextPage: res.page.hasNextPage,
      });
    })
  },


  //下拉刷新
  onPullDownRefresh: function() {
    this.refreshData();
    wx.stopPullDownRefresh()
  },

  refreshData: function() {
    this.setData({
      pageNo: 1
    })
    this.getlist();
  },

  //触底时，加载更多
  onReachBottom: function() {
    if (this.data.hasNextPage) {
      this.setData({
        pageNo: this.data.pageNo + 1
      });
      this.getlist();
    }
  },

  //取消关注
  delCustomerAttend: function(e) {
    var id = e.currentTarget.dataset.id;
    var that = this;

    wx.showModal({
      title: '提示',
      confirmText: '确定',
      cancelText: '取消',
      content: '确定取消关注该店铺',
      success: function (res) {
        if (res.confirm) {
          _wxRequest.wxTonkenAjax({
            url: app.globalData.apiUrl + '/org/protected/storeAttend/deleteUserAttend',
            method: 'post',
            contentType: 'application/x-www-form-urlencoded',
            data: {
              stoId: id,
              stoIdList: [id]
            }
          }, (res) => {
            that.getlist();
          })
        }
      }
    }) 



  },


})